function test()
	return 1, 2;
end
a, b = test();
print(a, b);

function search(p)					--查找最接近的坐标点 TODO网格切割
	min = 1000;
	r = 0;
	for i,v in ipairs(point) do
		l = math.sqrt(getlenp(v,p));
		if l < min then
			r = i;
			min = l;
		end
	end
	return r;
end

function getlenp(a, b)				--计算两点距离的平方
	if a == nil or b == nil then
		return 10000;
	end
	return math.pow(a.x - b.x, 2) + math.pow(a.y - b.y, 2);
end

function getlen(a, b)
	return math.sqrt(getlenp(a, b));	--计算两点距离
end

function normalize(a, b)				--归一化
	minDis = 0.01;
	if a == nil or b == nil then
		return 0, 0;
	end
	x = b.x - a.x;
	y = b.y - a.y;
	l = math.sqrt(x * x + y * y);
	if l < minDis then
		return 0, 0, 0;
	else
		return x / l, y / l, l;
		-- return a.x, b.x;
	end
end

function getMinRole(self, mons)				--获取距离最近的游戏玩家对象
	local max_Leng = 10000;
	local target_Role = nil;
	for i,v in pairs(mons) do
		local current_Length = getlenp(self, v);
		if current_Length < max_Leng then
			max_Leng = current_Length;
			target_Role = v;
		end
	end	
	return target_Role;
end


--叉积
function mult(a, b, c)
	return (a.x-c.x)*(b.y-c.y)-(b.x-c.x)*(a.y-c.y);
end

--aa, bb为一条线段两端点 cc, dd为另一条线段的两端点 相交返回true, 不相交返回false
function intersect(aa, bb, cc, dd)
	if math.max(aa.x, bb.x)<math.min(cc.x, dd.x) then
		return 0;
	end
	if math.max(aa.y, bb.y)<math.min(cc.y, dd.y) then
		return 0;
	end
	if math.max(cc.x, dd.x)<math.min(aa.x, bb.x) then
		return 0;
	end
	if math.max(cc.y, dd.y)<math.min(aa.y, bb.y) then
		return 0;
	end
	if mult(cc, bb, aa)*mult(bb, dd, aa)<0 then
		return 0;
	end
	if mult(aa, dd, cc)*mult(dd, bb, cc)<0 then
		return 0;
	end
	return 1;
end

function boxSolu(p, aa, bb, cc, dd)
	if intersect(p, aa, cc, bb) == 1 then
		return 0;
	end
	if intersect(p, aa, cc, dd) == 1 then
		return 0;
	end
	if intersect(p, bb, dd, aa) == 1 then
		return 0;
	end
	if intersect(p, bb, dd, cc) == 1 then
		return 0;
	end
	if intersect(p, cc, aa, bb) == 1 then
		return 0;
	end
	if intersect(p, cc, aa, dd) == 1 then
		return 0;
	end
	if intersect(p, dd, bb, aa) == 1 then
		return 0;
	end
	if intersect(p, dd, bb, cc) == 1 then
		return 0;
	end
	return 1;
end

function boxGetPoint(t, p, l, h)
	 -- Vector2 t = new Vector2(1, 0);//方向
     -- Vector2 p = new Vector2(0, 0);//位置
        -- float l = 10f;//长
        -- float h = 2f;//宽


        local a = t.x;
        local b = t.y;
        local y1 = math.sqrt(b * b + a * a) * a / (b * b + a * a);
        local x1 = -b * y1 / a;
        -- Vector2 v1 = new Vector2(x1, y1);
        local v1 = {x = x1, y = y1};
        local y2 = -math.sqrt(b * b + a * a) * a / (b * b + a * a);
        local x2 = -b * y2 / a;
        -- Vector2 v2 = new Vector2(x2, y2);
        local v2 = {x = x2, y = y2};

        -- Vector2 te = t * l / 2;
        local te = {x = t.x * l / 2, y = t.y * l / 2};
        -- Vector2 te2 = v1 * h / 2;
        local te2 = {x = v1.x * h / 2, y = v1.y * h / 2};
        -- Vector2 sum = te + te2;
        local sum = {x = te.x + te2.x, y = te.y + te2.y};
        -- Vector2 p1 = p + sum;
        local p1 = {x = p.x + sum.x, y = p.y + sum.y};
        -- te = t * l / 2;
        te.x = t.x * 1 / 2;		te.y = t.y * l / 2;
        -- te2 = v2 * h / 2;
        te2.x = v2.x * h / 2;	te2.y = v2.y * h / 2;
        -- sum = te + te2;
        sum.x = te.x + te2.x;	sum.y = te.y + te2.y;
        -- Vector2 p2 = p + sum;
        local p2 = {x = p.x + sum.x, y = p.y + sum.y};
        -- te = -t * l / 2;
        te.x = -t.x * l / 2;	te.y = -t.y * l / 2;
        -- te2 = v2 * h / 2;
        te2.x = v2.x * h / 2;	te2.y = v2.y * h / 2;
        -- sum = te + te2;
        sum.x = te.x + te2.x;	sum.y = te.y + te2.y;
        -- Vector2 p3 = p + sum;
        local p3 = {x = p.x + sum.x, y = p.y + sum.y};
        -- te = -t * l / 2;
        te.x = -t.x * l / 2;	te.y = -t.y * l / 2;
        -- te2 = v1 * h / 2;
        te2.x = v1.x * h / 2;	te2.y = v1.y * h / 2;
        -- sum = te + te2;
        sum.x = te.x + te2.x;	sum.y = te.y + te2.y;
        -- Vector2 p4 = p + sum;
        local p4 = {x = p.x + sum.x, y = p.y + sum.y};
        -- Debug.Log(p1 + "  " + p2 + "  " + p3 + "  " + p4);
        return p1, p2, p3, p4;

end
